#include<stdio.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<unistd.h>
#include<arpa/inet.h>
#include<sys/select.h>
#include<mysql.h>
#include<string.h>

struct password
{
	char id[20];
	char passwd[20];
	int flag;
};

void private_chat(int connectfd,struct password pw)
{
    	struct password Send;
	int new_fd;
    	MYSQL mysql;
    	MYSQL_ROW row;
    	MYSQL_RES *res = NULL;
    	char mysql_insert[100];
    	int rc,nflag=-1;
    	if(NULL == mysql_init(&mysql)) 
	{  
	        printf("mysql_init(): %s\n", mysql_error(&mysql));  
        	return -1;  
    	}  
    	if (NULL == mysql_real_connect(&mysql,  
			"localhost",  
                	"root",  
                	"root",  
                	"lts",  
                	 0,  
                	NULL,  
                	0)) 
	{  
        	printf("mysql_real_connect(): %s\n", mysql_error(&mysql));  
        	return;  
    	}  
    	sprintf(mysql_insert,"select * from user where username='%s'",pw.id);
    	rc = mysql_query(&mysql,mysql_insert);
	if(rc==0)
	{
		res = mysql_store_result(&mysql);
		row = mysql_fetch_row(res);
		new_fd=atoi(row[2]);
		if(new_fd==0)
		{
			send(connectfd,"The other party is not online",100,0);
		}
		send(new_fd,pw.passwd,sizeof(pw.passwd),0);
		
	}
	
}
